<!--
 * @Author: wangming
 * @Date: 2021-03-26 11:03:43
 * @LastEditors: wangming
 * @LastEditTime: 2022-07-21 17:23:57
 * @Description: file content
-->
<template>
  <div class="pht100 rel">
    <div class="tc del abs warntop bgwh" v-if="isTrial">
      您正在使用试用版，试用期剩余{{
        getAuthCenterInfo.nowExpiryDay
      }}天，请联系供应商授权。
    </div>
    <layout class="pht100" :class="{ pt40: isTrial }" ref="layout">
      <keep-alive :max="5">
        <router-view
          v-if="getAlive"
          :key="$route.fullPath"
          class="bgwh"
          :class="{ 'sz p10': !$route.meta.dynamic_page }"
        />
      </keep-alive>
      <router-view
        v-if="!getAlive"
        :key="$route.meta.dynamic_page ? $route.fullPath : undefined"
        class="bgwh"
        :class="{ 'sz p10': !$route.meta.dynamic_page }"
      />
    </layout>
  </div>
</template>

<script>
import { mapActions, mapGetters } from "vuex";
import layout from "./components/layout.vue";
import EventBus from "@/utils/eventBus";
export default {
  watch: {
    $route() {
      this.getAlive && this.setKeepAlive(false);
    },
  },
  created() {
    EventBus.$on("deleteTag", this.delTag.bind(this));
  },
  destroyed() {
    EventBus.$off("deleteTag");
  },
  methods: {
    ...mapActions(["setKeepAlive"]),
    delTag(path) {
      //保证在删除tag的时候清除keep-alive实例内缓存的页面信息
      let vNode = this.$refs.layout.$slots.default[0] || {};
      let keys = vNode?.componentInstance?.keys || [];
      let cache = vNode?.componentInstance?.cache || {};
      let delIndex = keys.indexOf(path);
      if (delIndex > -1) {
        keys.splice(delIndex, 1);
        delete cache[path];
      }
    },
  },
  components: { layout },
  computed: {
    ...mapGetters(["getAlive", "getAuthCenterInfo"]),
    isTrial() {
      return (
        process.env.VUE_APP_ROOT_URL === "./" &&
        (this.getAuthCenterInfo.status === "TRIAL" ||
          this.getAuthCenterInfo.status === "TEST")
      );
    },
  },
};
</script>
<style lang="scss" scoped>
.warntop {
  top: 0;
  width: 100%;
  height: 40px;
  line-height: 40px;
}
</style>
